<?php

use yii\helpers\Html;
use yii\bootstrap\ActiveForm;
use app\modules\cruise\models\Cruise;
use kartik\select2\Select2;

$cruise = Cruise::findOne($model->cruise_id);

// 创建选择楼层数组
$ceil = [];
for($i =1 ;$i<=$cruise->ceil; $i++){
    $ceil += [$i=>sprintf("%s层",$i)];
}

if(!is_array($model->ceil)){
   $model->ceil = json_decode($model->ceil); 
}
?>

<div class="room-form">

    <?php $form = ActiveForm::begin([
                                     'options' => ['enctype' => 'multipart/form-data',],
                                     'layout' => 'horizontal',
                                     'fieldConfig' => [
                                        'template' => "{label}\n{beginWrapper}\n{input}\n{hint}\n{error}\n{endWrapper}",
                                        'horizontalCssClasses' => [
                                            'label' => 'col-sm-2',
                                            'wrapper' => 'col-sm-7',
                                            'error' => '',
                                        ],
                                     ],
                                ]); ?>


    <?= $form->field($model, 'cruise_id')->label(false)->hiddenInput() ?>

    <?= $form->field($model, 'name')->textInput(['maxlength' => true]) ?>

    <?= $form->field($model, 'type')->inline(true)->radioList(\Yii::$app->params['room_type']) ?>

    <?= $form->field($model, 'code',['template'=>'{label}<div class="col-md-3">{input}{error}</div>{hint}'])->textInput() ?>

    <?= $form->field($model, 'area',['template'=>'{label}<div class="col-md-3">{input}{error}</div>{hint}'])->hint('平米')->textInput() ?>

    <?= $form->field($model, 'windows')->inline(true)->radioList(\Yii::$app->params['windows']) ?>


    <?= $form->field($model, 'balcony_area',['template'=>'{label}<div class="col-md-3">{input}{error}</div>{hint}'])->hint('平米')->textInput() ?>

    <?= $form->field($model, 'num',['template'=>'{label}<div class="col-md-3">{input}{error}</div>{hint}'])->hint('最大入住人数')->textInput() ?>

    <?= $form->field($model, 'min',['template'=>'{label}<div class="col-md-3">{input}{error}</div>{hint}'])->hint('最少入住人数')->textInput() ?>

    <?php echo $form->field($model, 'ceil')->widget(Select2::classname(), [
                'data' =>$ceil,
                'language' => 'zh-cn',
                'options' => ['multiple' => true, 'placeholder' => '选择楼层....'],
                'pluginOptions' => [
                    'allowClear' => true,
                    'closeOnSelect' => false
                ],
            ]) ?>


    <?= $form->field($model, 'status')->inline(true)->radioList(\Yii::$app->params['status']) ?>

    <?= $form->field($model, 'desc')->textArea(['maxlength' => true]) ?>

    <div class="form-group text-center">
        <?= Html::submitButton('保存', ['class' => 'btn btn-success']) ?>
    </div>

    <?php ActiveForm::end(); ?>

</div>
